#coding=utf-8

import stockdb.misc as misc
import strategy.basic as basic

def maxbmoney_filter(td, n=20):
    pre = td.pre
    if not pre:return None
    if td.max_bmoney > pre.top_maxmoney(n, 'b'):
        return True
    
    return False

if __name__ == '__main__':

    date = '2008-06-13'
    #date = misc.today
    n = 20
    print date
    tds = misc.find_tds_on(date)
    print len(tds)
    tf = basic.TDFilter(tds)

    tds = tf.filter_by(basic.tdattr_filter, 'change', -8, 11).\
             filter_by(basic.tdattr_filter, 'close', 5, 25).\
             filter_by(maxbmoney_filter, n).\
             all()
             
    for td in tds:
        s = td.fins
        pre = td.pre
        print s.code, s.name, int(td.max_bmoney/10000), int(pre.top_maxmoney(n, 'b')/10000) 
       
        
